# -*- coding: utf-8 -*-
import scrapy
from baidu.items import BaiduItem
import json


class NewSpider(scrapy.Spider):
    name = 'new'
    allowed_domains = ['baidu.com']
    start_urls = ['https://www.baidu.com/s?ie=UTF-8&wd=%E7%99%BE%E5%BA%A6']

    def parse(self, response):
        '''
        @url https://www.baidu.com/s?ie=UTF-8&wd=%E7%99%BE%E5%BA%A6
        @returns item
        :param response:
        :return:
        '''
        item = BaiduItem()
        item['names'] = response.xpath('//*[@class="opr-recommends-merge-panel opr-recommends-merge-mbGap" ][1]'
                                      '//*[@class="c-gap-top-small"]//a/text()').extract()
        # item['name_more'] = response.xpath('//*[@class="opr-recommends-merge-panel opr-recommends-merge-mbGap" ][1]'
        #                                    '//*[@class="opr-recommends-merge-width-text"]/text()').extract()
        item['hots'] = response.xpath('//*[@class="c-table opr-toplist1-table"]//span//a/text()').extract()
        # item['hot'] = None
        # for hot in item['hots']:
        #     print(hot)

        yield item
